//=============================================================================
/**
 *
 *	@file		museum_pokemon.c
 *	@brief		ポケスロン ポケモンレコード画面
 *	@author		hosaka genya
 *	@data		2008.09.04
 *
 */
//=============================================================================
#include "common.h"
#include "gflib/touchpanel.h"
#include "system/procsys.h"
#include "system/arc_util.h"
#include "system/arc_tool.h"
#include "system/brightness.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/window.h"
#include "system/pm_str.h"
#include "system/msgdata.h"
#include "system/wordset.h"
#include "system/fontproc.h"
#include "system/snd_tool.h"
#include "system/clact_util.h"
#include "system/clact_tool.h"
#include "system/render_oam.h"
#include "system/gra_tool.h"
#include "system/palanm.h"
#include "system/wipe.h"
#include "system/cursor_move.h"
#include "poketool/poke_tool.h"
#include "poketool/pokeicon.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_pokethlon_museum.h"

#include "application/app_tool.h"
#include "application/museum.h"

#include "museum_util.h"
#include "museum_obj.h"
#include "museum_bg.h"

#include "system/pm_overlay.h"

#include "../zukanlist/zkn_data/zukan_data.naix"
#include "pkth_museum.naix"
#include "obj_trophy_NANR_LBLDEFS.h"

#include "gs_bugfix.h"

FS_EXTERN_OVERLAY(pkthln_common);

//=============================================================================
/**
 *								定数定義
 */
//=============================================================================

//--------------------------------------------------------------
///	BG関係のENUM
//==============================================================
enum
{
	BMPWIN_M_CGX = 1,
	BMPWIN_S_CGX = 1,

	BG_USE_NUM	= 7,
	// frame
	FRM_M_BASE	= GF_BGL_FRAME0_M,
	FRM_M_TEXT	= GF_BGL_FRAME1_M,
	FRM_M_BOX	= GF_BGL_FRAME2_M,
	FRM_M_RIBBON = GF_BGL_FRAME3_M,
	FRM_S_BASE	= GF_BGL_FRAME0_S,
	FRM_S_TEXT	= GF_BGL_FRAME1_S,
	FRM_S_RIBBON = GF_BGL_FRAME2_S,
	// mask
	FRM_S_RIBBON_DISP = GX_PLANEMASK_BG2,

	FONT_RIBBON_PAL			= 1,	///< リボンに使用するパレットのオフセット
	FONT_POS_RIBBON_BACK	= 3,	///< リボンの上に表示する文字のバックカラー

	BG_M_CGX_RIBBON_HEAD	= 1,	///< BGリボンの先頭キャラ

	OBJ_BGPRI_POKEICON		= 1,	///< ポケアイコンのBGPRI

	MEDAL_MAX = 5,				///< メダルの最大数
};

// -- 使用するBGテーブル
static const u8 c_BG_UseList[ BG_USE_NUM ] = {
	GF_BGL_FRAME0_M, GF_BGL_FRAME1_M, GF_BGL_FRAME2_M, GF_BGL_FRAME3_M,
	GF_BGL_FRAME0_S, GF_BGL_FRAME1_S, GF_BGL_FRAME2_S,
};

//--------------------------------------------------------------
///	OBJ_ID
//==============================================================
enum {
	OBJ_POKEICON_ROW	= 6,
	OBJ_POKEICON_LINE	= 5,
	OBJ_POKEICON_MAX	= OBJ_POKEICON_ROW * OBJ_POKEICON_LINE,
	OBJ_MEDAL_MAX		= OBJ_ANM_MEDAL_MAX,
	OBJ_MATER_NUM = 10,

	// -- Main LCD --
	OBJ_ID_M_CURSOR = 0,
	OBJ_ID_M_ARROW_L,
	OBJ_ID_M_ARROW_R,
	OBJ_ID_S_POKEGRA,
	OBJ_ID_COMMON_MAX,
	OBJ_ID_M_MATER_HEAD,
	OBJ_ID_S_MEDAL_HEAD		= OBJ_ID_M_MATER_HEAD + OBJ_MATER_NUM,
	OBJ_ID_M_POKEICON_HEAD	= OBJ_ID_S_MEDAL_HEAD + OBJ_MEDAL_MAX,
	OBJ_ID_MAX				= OBJ_ID_M_POKEICON_HEAD + OBJ_POKEICON_MAX,

	// -- obj pos --
	OBJPOS_ARROW_L_X = 16,
	OBJPOS_ARROW_R_X = 240,
	OBJPOS_ARROW_Y = 84,
};

//--------------------------------------------------------------
///	OBJ用：リソースID
//==============================================================
enum {
	CHR_ID_M_POKEREC = 0,
	CHR_ID_M_TROPHY,
	CHR_ID_M_POKEICON_HEAD,
	CHR_ID_S_MEDAL = CHR_ID_M_POKEICON_HEAD + OBJ_POKEICON_MAX,
	CHR_ID_S_POKEGRA,
	CHR_ID_MAX,
};

enum {
	PAL_ID_M_POKEREC = 0,
	PAL_ID_M_POKEICON,
	PAL_ID_M_TROPHY,
	PAL_ID_S_MEDAL,
	PAL_ID_S_POKEGRA,
	PAL_ID_MAX,
};

enum {
	CEL_ID_POKEREC = 0,
	CEL_ID_POKEICON,
	CEL_ID_TROPHY,
	CEL_ID_MEDAL,
	CEL_ID_POKEGRA,
	CEL_ID_MAX,
};

enum {
	ANM_ID_POKEREC = 0,
	ANM_ID_POKEICON,
	ANM_ID_TROPHY,
	ANM_ID_MEDAL,
	ANM_ID_POKEGRA,
	ANM_ID_MAX,
};

//--------------------------------------------------------------
///	BMPWIN用IDX
//==============================================================
enum
{
	// Main LCD
	BMPWIN_ID_M_MODE_CAP = 0,
	BMPWIN_ID_M_MDLIST_CNT,
	BMPWIN_ID_M_TROPHY_TAR,
	BMPWIN_ID_M_PAGE,
	BMPWIN_ID_M_RETURN,
	// Sub LCD
	BMPWIN_ID_S_PKNAME,
	BMPWIN_ID_S_PKNAME_CAP,
	BMPWIN_ID_S_MDL_SPD,
	BMPWIN_ID_S_MDL_POW,
	BMPWIN_ID_S_MDL_TEC,
	BMPWIN_ID_S_MDL_STA,
	BMPWIN_ID_S_MDL_JMP,
	BMPWIN_ID_S_MDLST_CAP,
	BMPWIN_ID_MAX,
};


//=============================================================================
/**
 *								構造体定義
 */
//=============================================================================

//--------------------------------------------------------------
///	メインワーク
//==============================================================
typedef struct {
	GF_BGL_INI*		p_bgl;
	ARCHANDLE*		p_arc_pkth_museum;
	ARCHANDLE*		p_arc_zkn;
	HEAPID			heapID;
	const PKTH_MUSEUM_PK_PARAM* p_prm;

	// -- 参照データ --
	u16				c_draw_pklist[ MONSNO_END ];	///< 描画するポケモンのIDを保存
	u16*			cp_pklist;						///< 図鑑のソートデータ （動的メモリ使用）
	u32				c_page_max		: 5;			///< ページ数
	u32				c_poke_max		: 9;			///< メダルを持っているポケモンの数
	// -- ローカルデータ --
	u32				page_pos		: 5;			///< 現在のページ
	u32				cur_pos			: 8;			///< カーソルの位置 (CURSOR_MOVE_WORKで使用)
	u32				b_page_move_right : 1;			///< ページの移動方向フラグ(TRUE:右へ）
	u32				b_page_flash	: 1;			///< ページ更新フラグ
	u32				b_element_flash	: 1;			///< 要素更新フラグ
	u32				dummy			: 2;

	u32				page_cnt		: 8;			///< ページ移動時に使用するカウンタ
	u32				dummy2			: 24;

	CURSOR_MOVE_WORK*	wk_cur;
	MUSEUM_MSG_WORK*	wk_msg;
	MUSEUM_OBJ_WORK*	wk_obj;
	CATS_ACT_PTR		cap[ OBJ_ID_MAX ];
} MUSEUM_PK_WORK;

//=============================================================================
/**
 *								データテーブル
 */
//=============================================================================

#define BMP_STRING_H	( 2 )

// main
#define BMP_M_MODE_CAP_W	( 12 )
#define BMP_M_MDLST_NUM_W	( 18 )
#define BMP_M_TRPTAR_W		( 24 )
#define BMP_M_PAGE_W		( 5 )
#define BMP_M_RETURN_W		( 6 )
// sub
#if GS_AFTERMASTER_GF1043_20090910_FIX
  #define BMP_S_PKNAME_W		( 8 )
#else
  #define BMP_S_PKNAME_W		( MONS_DISP_SIZE + 2 ) // MONS_DISP_SIZE=5
#endif

#define BMP_S_PKNAME_C_W	( 12 )
#define BMP_S_MDL_W			( 11 )

// cgx main
#define BMP_M_MODE_CAP_CGX	( BMPWIN_M_CGX )
#define BMP_M_MDLST_NUM_CGX	( BMP_M_MODE_CAP_CGX	+ BMP_STRING_H * BMP_M_MODE_CAP_W )
#define BMP_M_TRPTAR_CGX	( BMP_M_MDLST_NUM_CGX	+ BMP_STRING_H * BMP_M_MDLST_NUM_W )
#define BMP_M_PAGE_CGX		( BMP_M_TRPTAR_CGX		+ BMP_STRING_H * BMP_M_TRPTAR_W )
#define BMP_M_RETURN_CGX	( BMP_M_PAGE_CGX		+ BMP_STRING_H * BMP_M_PAGE_W )
// cgx sub
#define BMP_S_PKNAME_CGX	( BMPWIN_S_CGX )
#define BMP_S_PKNAME_C_CGX	( BMP_S_PKNAME_CGX		+ BMP_STRING_H * BMP_S_PKNAME_W )
#define BMP_S_MDL_SPD_CGX	( BMP_S_PKNAME_C_CGX	+ BMP_STRING_H * BMP_S_PKNAME_C_W )
#define BMP_S_MDL_POW_CGX	( BMP_S_MDL_SPD_CGX		+ BMP_STRING_H * BMP_S_MDL_W )
#define BMP_S_MDL_TEC_CGX	( BMP_S_MDL_POW_CGX		+ BMP_STRING_H * BMP_S_MDL_W )
#define BMP_S_MDL_STA_CGX	( BMP_S_MDL_TEC_CGX		+ BMP_STRING_H * BMP_S_MDL_W )
#define BMP_S_MDL_JMP_CGX	( BMP_S_MDL_STA_CGX		+ BMP_STRING_H * BMP_S_MDL_W )

// 上画面：リボンの「メダリストポケモン」
#define BMP_STRING_2LINE_H	( 4 )
#define BMP_S_MDLST_CAP_W	( 6 )
#define BMP_S_MDLST_CAP_CGX	( 512 )	// FRM_S_RIBBONのCGXに書き込む。これだけ空けて置けば大丈夫だろう・・。

//--------------------------------------------------------------
///	BMPWIN用 データテーブル
//==============================================================
static const BMPWIN_DAT c_BmpWinList[ BMPWIN_ID_MAX ] =
{
	// -- main --
	{ FRM_M_TEXT,	0,	0,	BMP_M_MODE_CAP_W,	BMP_STRING_H, FONT_TALK_PAL, BMP_M_MODE_CAP_CGX, },	// BMPWIN_ID_M_MODE_CAP
	{ FRM_M_TEXT,	0,	20,	BMP_M_MDLST_NUM_W,	BMP_STRING_H, FONT_TALK_PAL, BMP_M_MDLST_NUM_CGX, },// BMPWIN_ID_M_MDLIST_CNT
	{ FRM_M_TEXT,	0,	22,	BMP_M_TRPTAR_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_M_TRPTAR_CGX, },	// BMPWIN_ID_M_TROPHY_TAR
	{ FRM_M_TEXT,	15,	0,	BMP_M_PAGE_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_M_PAGE_CGX, },		// BMPWIN_ID_M_PAGE
	{ FRM_M_TEXT,	26,	21,	BMP_M_RETURN_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_M_RETURN_CGX, },	// BMPWIN_ID_M_RETURN
	// -- sub --
	{ FRM_S_TEXT,	7,	1,	BMP_S_PKNAME_W,		BMP_STRING_H,	FONT_TALK_PAL,	BMP_S_PKNAME_CGX, },	// BMPWIN_ID_S_PKNAME
	{ FRM_S_TEXT,	14,	1,	BMP_S_PKNAME_C_W,	BMP_STRING_H,	FONT_TALK_PAL,	BMP_S_PKNAME_C_CGX, },	// BMPWIN_ID_S_PKNAME_CAP
	{ FRM_S_TEXT,	15,	5,	BMP_S_MDL_W,	BMP_STRING_H,	FONT_TALK_PAL,	BMP_S_MDL_SPD_CGX, },	// BMPWIN_ID_S_MDL_SPD
	{ FRM_S_TEXT,	17,	9,	BMP_S_MDL_W,	BMP_STRING_H,	FONT_TALK_PAL,	BMP_S_MDL_POW_CGX, },	// BMPWIN_ID_S_MDL_POW
	{ FRM_S_TEXT,	18,	13,	BMP_S_MDL_W,	BMP_STRING_H,	FONT_TALK_PAL,	BMP_S_MDL_TEC_CGX, },	// BMPWIN_ID_S_MDL_TEC
	{ FRM_S_TEXT,	17,	17,	BMP_S_MDL_W,	BMP_STRING_H,	FONT_TALK_PAL,	BMP_S_MDL_STA_CGX, },	// BMPWIN_ID_S_MDL_STA
	{ FRM_S_TEXT,	15,	21,	BMP_S_MDL_W,	BMP_STRING_H,	FONT_TALK_PAL,	BMP_S_MDL_JMP_CGX, },	// BMPWIN_ID_S_MDL_JMP
	// -- sub_ribbon --
	{ FRM_S_RIBBON, 3,	18,	BMP_S_MDLST_CAP_W,	BMP_STRING_2LINE_H,	FONT_RIBBON_PAL,	BMP_S_MDLST_CAP_CGX },	// BMPWIN_ID_S_MDLST_CAP
};


//--------------------------------------------------------------
// カーソル定義
//--------------------------------------------------------------
#define	OBJ_TRAYPOKE_PX		( 6*8 )		// トレイのポケモンアイコン表示開始Ｘ座標
#define	OBJ_TRAYPOKE_PY		( 5*8 )		// トレイのポケモンアイコン表示開始Ｙ座標
#define	OBJ_TRAYPOKE_SX		( 4*8 )		// トレイのポケモンアイコンＸサイズ
#define	OBJ_TRAYPOKE_SY		( 3*8 )		// トレイのポケモンアイコンＹサイズ

#define	TRAYPOKE_SIZE_X		( OBJ_TRAYPOKE_SX )
#define	TRAYPOKE_SIZE_Y		( OBJ_TRAYPOKE_SY )
#define	TRAYPOKE_START_X	( OBJ_TRAYPOKE_PX - TRAYPOKE_SIZE_X / 2 )
#define	TRAYPOKE_START_Y	( OBJ_TRAYPOKE_PY - TRAYPOKE_SIZE_Y / 2 )
#define	TRAYPOKE_PX(a)		( TRAYPOKE_START_X + TRAYPOKE_SIZE_X * a )
#define	TRAYPOKE_PY(a)		( TRAYPOKE_START_Y + TRAYPOKE_SIZE_Y * a )

#define	PICUR_X		( 2*8 )
#define	PICUR_Y		( 1*8 )

static const POINTER_WORK c_cur_pos[] =
{
	{ TRAYPOKE_PX(0)+PICUR_X,TRAYPOKE_PY(0)+PICUR_Y, 0, 0,	0,  6, 0, 1 },		// 00: ポケモン
	{ TRAYPOKE_PX(1)+PICUR_X,TRAYPOKE_PY(0)+PICUR_Y, 0, 0,	1,  7, 0, 2 },
	{ TRAYPOKE_PX(2)+PICUR_X,TRAYPOKE_PY(0)+PICUR_Y, 0, 0,	2,  8, 1, 3 },
	{ TRAYPOKE_PX(3)+PICUR_X,TRAYPOKE_PY(0)+PICUR_Y, 0, 0,	3,  9, 2, 4 },
	{ TRAYPOKE_PX(4)+PICUR_X,TRAYPOKE_PY(0)+PICUR_Y, 0, 0,	4, 10, 3, 5 },
	{ TRAYPOKE_PX(5)+PICUR_X,TRAYPOKE_PY(0)+PICUR_Y, 0, 0,	5, 11, 4, 5 },

	{ TRAYPOKE_PX(0)+PICUR_X,TRAYPOKE_PY(1)+PICUR_Y, 0, 0,	0, 12,  6,  7 },	// 06: ポケモン
	{ TRAYPOKE_PX(1)+PICUR_X,TRAYPOKE_PY(1)+PICUR_Y, 0, 0,	1, 13,  6,  8 },
	{ TRAYPOKE_PX(2)+PICUR_X,TRAYPOKE_PY(1)+PICUR_Y, 0, 0,	2, 14,  7,  9 },
	{ TRAYPOKE_PX(3)+PICUR_X,TRAYPOKE_PY(1)+PICUR_Y, 0, 0,	3, 15,  8, 10 },
	{ TRAYPOKE_PX(4)+PICUR_X,TRAYPOKE_PY(1)+PICUR_Y, 0, 0,	4, 16,  9, 11 },
	{ TRAYPOKE_PX(5)+PICUR_X,TRAYPOKE_PY(1)+PICUR_Y, 0, 0,	5, 17, 10, 11 },

	{ TRAYPOKE_PX(0)+PICUR_X,TRAYPOKE_PY(2)+PICUR_Y, 0, 0,	 6, 18, 12, 13 },	// 12: ポケモン
	{ TRAYPOKE_PX(1)+PICUR_X,TRAYPOKE_PY(2)+PICUR_Y, 0, 0,	 7, 19, 12, 14 },
	{ TRAYPOKE_PX(2)+PICUR_X,TRAYPOKE_PY(2)+PICUR_Y, 0, 0,	 8, 20, 13, 15 },
	{ TRAYPOKE_PX(3)+PICUR_X,TRAYPOKE_PY(2)+PICUR_Y, 0, 0,	 9, 21, 14, 16 },
	{ TRAYPOKE_PX(4)+PICUR_X,TRAYPOKE_PY(2)+PICUR_Y, 0, 0,	10, 22, 15, 17 },
	{ TRAYPOKE_PX(5)+PICUR_X,TRAYPOKE_PY(2)+PICUR_Y, 0, 0,	11, 23, 16, 17 },

	{ TRAYPOKE_PX(0)+PICUR_X,TRAYPOKE_PY(3)+PICUR_Y, 0, 0,	12, 24, 18, 19 },	// 18: ポケモン
	{ TRAYPOKE_PX(1)+PICUR_X,TRAYPOKE_PY(3)+PICUR_Y, 0, 0,	13, 25, 18, 20 },
	{ TRAYPOKE_PX(2)+PICUR_X,TRAYPOKE_PY(3)+PICUR_Y, 0, 0,	14, 26, 19, 21 },
	{ TRAYPOKE_PX(3)+PICUR_X,TRAYPOKE_PY(3)+PICUR_Y, 0, 0,	15, 27, 20, 22 },
	{ TRAYPOKE_PX(4)+PICUR_X,TRAYPOKE_PY(3)+PICUR_Y, 0, 0,	16, 28, 21, 23 },
	{ TRAYPOKE_PX(5)+PICUR_X,TRAYPOKE_PY(3)+PICUR_Y, 0, 0,	17, 29, 22, 23 },

	{ TRAYPOKE_PX(0)+PICUR_X,TRAYPOKE_PY(4)+PICUR_Y, 0, 0,	18, 30, 24, 25 },	// 24: ポケモン
	{ TRAYPOKE_PX(1)+PICUR_X,TRAYPOKE_PY(4)+PICUR_Y, 0, 0,	19, 30, 24, 26 },
	{ TRAYPOKE_PX(2)+PICUR_X,TRAYPOKE_PY(4)+PICUR_Y, 0, 0,	20, 30, 25, 27 },
	{ TRAYPOKE_PX(3)+PICUR_X,TRAYPOKE_PY(4)+PICUR_Y, 0, 0,	21, 30, 26, 28 },
	{ TRAYPOKE_PX(4)+PICUR_X,TRAYPOKE_PY(4)+PICUR_Y, 0, 0,	22, 30, 27, 29 },
	{ TRAYPOKE_PX(5)+PICUR_X,TRAYPOKE_PY(4)+PICUR_Y, 0, 0,	23, 30, 28, 29 },

	{ 224,	176, 0, 0,	CURSORMOVE_RETBIT|29, 30, 30, 30 },						// 30: もどる
};

enum
{
	CURID_POKE_MAX	= OBJ_POKEICON_MAX,
	CURID_RETURN	= CURID_POKE_MAX,
};

static const RECT_HIT_TBL c_cur_hit[] =
{
	{ TRAYPOKE_PY(0), TRAYPOKE_PY(1)-1, TRAYPOKE_PX(0),	TRAYPOKE_PX(1)-1 },		// 00: ポケモン
	{ TRAYPOKE_PY(0), TRAYPOKE_PY(1)-1, TRAYPOKE_PX(1),	TRAYPOKE_PX(2)-1 },
	{ TRAYPOKE_PY(0), TRAYPOKE_PY(1)-1, TRAYPOKE_PX(2),	TRAYPOKE_PX(3)-1 },
	{ TRAYPOKE_PY(0), TRAYPOKE_PY(1)-1, TRAYPOKE_PX(3),	TRAYPOKE_PX(4)-1 },
	{ TRAYPOKE_PY(0), TRAYPOKE_PY(1)-1, TRAYPOKE_PX(4),	TRAYPOKE_PX(5)-1 },
	{ TRAYPOKE_PY(0), TRAYPOKE_PY(1)-1, TRAYPOKE_PX(5),	TRAYPOKE_PX(6)-1 },

	{ TRAYPOKE_PY(1), TRAYPOKE_PY(2)-1, TRAYPOKE_PX(0),	TRAYPOKE_PX(1)-1 },
	{ TRAYPOKE_PY(1), TRAYPOKE_PY(2)-1, TRAYPOKE_PX(1),	TRAYPOKE_PX(2)-1 },
	{ TRAYPOKE_PY(1), TRAYPOKE_PY(2)-1, TRAYPOKE_PX(2),	TRAYPOKE_PX(3)-1 },
	{ TRAYPOKE_PY(1), TRAYPOKE_PY(2)-1, TRAYPOKE_PX(3),	TRAYPOKE_PX(4)-1 },
	{ TRAYPOKE_PY(1), TRAYPOKE_PY(2)-1, TRAYPOKE_PX(4),	TRAYPOKE_PX(5)-1 },
	{ TRAYPOKE_PY(1), TRAYPOKE_PY(2)-1, TRAYPOKE_PX(5),	TRAYPOKE_PX(6)-1 },

	{ TRAYPOKE_PY(2), TRAYPOKE_PY(3)-1, TRAYPOKE_PX(0),	TRAYPOKE_PX(1)-1 },
	{ TRAYPOKE_PY(2), TRAYPOKE_PY(3)-1, TRAYPOKE_PX(1),	TRAYPOKE_PX(2)-1 },
	{ TRAYPOKE_PY(2), TRAYPOKE_PY(3)-1, TRAYPOKE_PX(2),	TRAYPOKE_PX(3)-1 },
	{ TRAYPOKE_PY(2), TRAYPOKE_PY(3)-1, TRAYPOKE_PX(3),	TRAYPOKE_PX(4)-1 },
	{ TRAYPOKE_PY(2), TRAYPOKE_PY(3)-1, TRAYPOKE_PX(4),	TRAYPOKE_PX(5)-1 },
	{ TRAYPOKE_PY(2), TRAYPOKE_PY(3)-1, TRAYPOKE_PX(5),	TRAYPOKE_PX(6)-1 },

	{ TRAYPOKE_PY(3), TRAYPOKE_PY(4)-1, TRAYPOKE_PX(0),	TRAYPOKE_PX(1)-1 },
	{ TRAYPOKE_PY(3), TRAYPOKE_PY(4)-1, TRAYPOKE_PX(1),	TRAYPOKE_PX(2)-1 },
	{ TRAYPOKE_PY(3), TRAYPOKE_PY(4)-1, TRAYPOKE_PX(2),	TRAYPOKE_PX(3)-1 },
	{ TRAYPOKE_PY(3), TRAYPOKE_PY(4)-1, TRAYPOKE_PX(3),	TRAYPOKE_PX(4)-1 },
	{ TRAYPOKE_PY(3), TRAYPOKE_PY(4)-1, TRAYPOKE_PX(4),	TRAYPOKE_PX(5)-1 },
	{ TRAYPOKE_PY(3), TRAYPOKE_PY(4)-1, TRAYPOKE_PX(5),	TRAYPOKE_PX(6)-1 },

	{ TRAYPOKE_PY(4), TRAYPOKE_PY(5)-1, TRAYPOKE_PX(0),	TRAYPOKE_PX(1)-1 },
	{ TRAYPOKE_PY(4), TRAYPOKE_PY(5)-1, TRAYPOKE_PX(1),	TRAYPOKE_PX(2)-1 },
	{ TRAYPOKE_PY(4), TRAYPOKE_PY(5)-1, TRAYPOKE_PX(2),	TRAYPOKE_PX(3)-1 },
	{ TRAYPOKE_PY(4), TRAYPOKE_PY(5)-1, TRAYPOKE_PX(3),	TRAYPOKE_PX(4)-1 },
	{ TRAYPOKE_PY(4), TRAYPOKE_PY(5)-1, TRAYPOKE_PX(4),	TRAYPOKE_PX(5)-1 },
	{ TRAYPOKE_PY(4), TRAYPOKE_PY(5)-1, TRAYPOKE_PX(5),	TRAYPOKE_PX(6)-1 },

	{ 160,	160+31,	192, 192+63, },		// 30: もどる

	{ RECT_HIT_END, 0, 0, 0 }
};

static const RECT_HIT_TBL c_page_hit[] =
{
	{ 68,	 68+31,	0,	 0+31, },		// トレイ切り替え矢印・左
	{ 68,	 68+31,	224, 224+31, },		// トレイ切り替え矢印・右
	{ TP_HIT_END, 0, 0, 0 },
};

enum {
	BTN_IDX_PAGE_LEFT = 0,
	BTN_IDX_PAGE_RIGHT,
};


// 同時押しは排除
#define CHECK_REPEAT(key) ( sys.repeat == key )



//=============================================================================
/**
 *							プロトタイプ宣言
 */
//=============================================================================
// -- prototype --
static const BOOL is_zenkoku( MUSEUM_PK_WORK* wk );
static const BOOL is_museum_open( MUSEUM_PK_WORK* wk );
static const u8 get_page_poke_cnt( MUSEUM_PK_WORK* wk );
static const u8 get_medal_dat( MUSEUM_PK_WORK* wk, u16 monsno );
static const u16 get_medalist_cnt( MUSEUM_PK_WORK* wk );
static const BOOL is_medalist( MUSEUM_PK_WORK* wk, u16 monsno );
static const u16 get_select_monsno( MUSEUM_PK_WORK* wk );
static void medal_check( MUSEUM_PK_WORK* wk, u16 monsno );
static u16* sort_data_load( MUSEUM_PK_WORK* wk, u32* p_max );
static void data_setup( MUSEUM_PK_WORK* wk );
static void bg_ribbon_write( MUSEUM_PK_WORK* wk, s16 px, s16 py );
static void bg_ribbon_flash( MUSEUM_PK_WORK* wk, u16 idx, u16 monsno );
static void pokeicon_enable( MUSEUM_PK_WORK* wk, BOOL b_enable );
static void pokeicon_flash( MUSEUM_PK_WORK* wk );
static void page_flash( MUSEUM_PK_WORK* wk );
static BOOL page_change( MUSEUM_PK_WORK* wk );
static void pokegra_flash( MUSEUM_PK_WORK* wk, u16 monsno );
static void element_flash( MUSEUM_PK_WORK* wk );
static void element_null( MUSEUM_PK_WORK* wk );
PROC_RESULT MuseumPokemonProc_Init( PROC *proc, int *seq);
PROC_RESULT MuseumPokemonProc_End( PROC *proc,int *seq);
PROC_RESULT MuseumPokemonProc_Main( PROC *proc,int *seq);
static void COMMON_VBlank( void* work );
static void CURSOR_Init( MUSEUM_PK_WORK* wk );
static void CURSOR_Release( MUSEUM_PK_WORK* wk );
static void page_move( MUSEUM_PK_WORK* wk, BOOL b_right, BOOL b_touch );
static void check_page_change( MUSEUM_PK_WORK* wk, int now_pos );
static BOOL CURSOR_Main( MUSEUM_PK_WORK* wk );
static void CursorObjMove( MUSEUM_PK_WORK* wk, int pos );
static void CursorMoveCallBack_On( void * work, int now_pos, int old_pos );
static void CursorMoveCallBack_Off( void * work, int now_pos, int old_pos );
static void CursorMoveCallBack_Move( void * work, int now_pos, int old_pos );
static void CursorMoveCallBack_Touch( void * work, int now_pos, int old_pos );
static void cursor_move( MUSEUM_PK_WORK* wk, int now_pos, int old_pos, BOOL b_touch );
static void BG_Init( MUSEUM_PK_WORK* wk );
static void BG_LoadRes( MUSEUM_PK_WORK* wk );
static void BG_Release( MUSEUM_PK_WORK* wk );
static void OBJ_Init( MUSEUM_PK_WORK* wk );
static void OBJ_PokegraLoadResDummy( MUSEUM_PK_WORK* wk );
static void OBJ_LoadRes( MUSEUM_PK_WORK* wk );
static void OBJ_AddCommon( MUSEUM_PK_WORK* wk );
static void OBJ_AddMedal( MUSEUM_PK_WORK* wk );
static void OBJ_AddPokeIcon( MUSEUM_PK_WORK* wk );
static void PRINT_StaticMessage( MUSEUM_PK_WORK* wk );


//=============================================================================
/**
 *								データ取得関数
 */
//=============================================================================
// @@@ 複数回評価される関数が多々ある。重いようならget関数とcalc関数に分ける。

static const BOOL is_zenkoku( MUSEUM_PK_WORK* wk )
{
	// ジョウド図鑑に登録されていないポケモンが表示されなくなってしまうため、常に全国図鑑表示にした
	return 1;
//	return wk->p_prm->b_zukan_zenkoku;
}

static const BOOL is_museum_open( MUSEUM_PK_WORK* wk )
{
	return wk->p_prm->b_museum_open;
}

static const u8 get_page_poke_cnt( MUSEUM_PK_WORK* wk )
{
	if( wk->page_pos == wk->c_page_max )
	{
		u8 ret = wk->c_poke_max % OBJ_POKEICON_MAX;
		if( ret ){ return ret; }
	}
	return OBJ_POKEICON_MAX;
}

static const u8 get_medal_dat( MUSEUM_PK_WORK* wk, u16 monsno )
{
	return wk->p_prm->p_medal_dat[ monsno-1 ];
}

static const u16 get_medalist_cnt( MUSEUM_PK_WORK* wk )
{
	return MUSEUM_UTIL_GetMedalistPokemonCount( wk->p_prm->p_medal_dat );
}

static const BOOL is_medalist( MUSEUM_PK_WORK* wk, u16 monsno )
{
	return MATH_CountPopulation( get_medal_dat( wk, monsno ) ) == MEDAL_MAX;
}

static const u16 get_select_monsno( MUSEUM_PK_WORK* wk )
{
	int offset = wk->page_pos * OBJ_POKEICON_MAX + wk->cur_pos;

#ifdef GS_BTS5522_20090708_FIX
	if( offset >= MONSNO_END )
	{
		HOSAKA_PRINT("over offset=%d \n", offset);
		return 0;
	}
#endif

//	HOSAKA_PRINT( "select_monsno:%d \n", wk->c_draw_pklist[ offset ] );

	return wk->c_draw_pklist[ offset ];
}

static const ZUKAN_WORK* get_zukan_work( MUSEUM_PK_WORK* wk )
{
	return wk->p_prm->p_zkn;
}

static const u32 get_poke_form( MUSEUM_PK_WORK* wk, u16 monsno )
{
	if( monsno == 0 || monsno > MONSNO_END ){ return 0; }
	return ZukanWork_GetPokeForm( get_zukan_work( wk ), monsno, 0 );
}

static const u32 get_poke_sex( MUSEUM_PK_WORK* wk, u16 monsno )
{
	u32 ret;

	if( monsno == 0 || monsno > MONSNO_END ){ return 0; }
	ret = ZukanWork_GetPokeSexFlag( get_zukan_work( wk ), monsno, ZUKAN_WORK_SEX_FIRST );

	// 念のためハングしないように
	if( ret == ZUKAN_WORK_GET_SEX_ERR ){ ret = PokeSexGetMonsNo( monsno, 0 ); }

	return ret;
}

static u32 get_pattiru_rand( MUSEUM_PK_WORK* wk )
{
	return ZukanWork_GetPokeRandomFlag( get_zukan_work( wk ), ZUKAN_WORK_RANDOM_PACHI );
}

static u32 get_trophy_num( MUSEUM_PK_WORK* wk )
{
	return MUSEUM_UTIL_GetPokemonTrophyCount( get_medalist_cnt( wk ) );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	獲得したメダルを表示
 *
 *	@param	MUSEUM_PK_WORK* wk
 *	@param	monsno
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void medal_check( MUSEUM_PK_WORK* wk, u16 monsno )
{
	u8 i;
	u8 mdl_dat;

	mdl_dat = get_medal_dat( wk, monsno );

//	HOSAKA_PRINT("monsno:%d mdl_dat:%d \n",monsno, mdl_dat);

	for( i=0; i<MEDAL_MAX; i++ )
	{
		CATS_ObjectEnableCap( wk->cap[ OBJ_ID_S_MEDAL_HEAD + i ], ( mdl_dat & 1 ) );
		mdl_dat >>= 1;
	}
}

//--------------------------------------------------------------------------------------------
/**
 *	ソートリストデータ読み込み
 *
 *	@param	MUSEUM_PK_WORK* wk
 *	@param	p_max			[out] 配列の要素数
 *
 *	@return	読み込みデータバッファ
 *
 */
//--------------------------------------------------------------------------------------------
static u16* sort_data_load( MUSEUM_PK_WORK* wk, u32* p_max )
{
	static const dat_idx[] =
	{
		NARC_zukan_data_zkn_sort_shinoh_dat,
		NARC_zukan_data_zkn_sort_zenkoku_dat,
	};

	u16 * buf;
	u32	siz;

	// 読み込み
	buf = ArcUtil_HDL_LoadEx(
			wk->p_arc_zkn,
			dat_idx[ is_zenkoku( wk ) ],
			FALSE,
			wk->heapID,
			ALLOC_TOP,
			&siz );

	*p_max = siz / sizeof(u16);

	return buf;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	この画面に必要なデータを計算しておく
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void data_setup( MUSEUM_PK_WORK* wk )
{
	int i;
	u32 pklist_cnt;

	// 図鑑のソートデータをロード
	wk->cp_pklist = sort_data_load( wk, &pklist_cnt );

	// メダルを持っているポケモンのIDテーブルを作成
	for( i=0; i<pklist_cnt; i++ )
	{
		u16 monsno = wk->cp_pklist[ i ];
		u8 mdl_dat;

		GF_ASSERT( monsno > 0 && monsno <= MONSNO_END );

		mdl_dat = get_medal_dat( wk, monsno );

		// メダルを取得しているか判定
		if( mdl_dat )
		{
			wk->c_draw_pklist[ wk->c_poke_max ] = monsno;

			// ついでにポケモン数を計算
			wk->c_poke_max++;
		}
	}

	// ページ数を計算
	if( wk->c_poke_max > 0 )
	{
		wk->c_page_max =  wk->c_poke_max / OBJ_POKEICON_MAX;

		// 割り切れた状態ならページ数は増やさない
		if( wk->c_poke_max % OBJ_POKEICON_MAX == 0 )
		{
			wk->c_page_max -= 1;
		}
	}

	HOSAKA_PRINT("c_poke_max:%d c_page_max:%d \n", wk->c_poke_max, wk->c_page_max );
}

//===============================================================
// BG RIBBON
//===============================================================
//-----------------------------------------------------------------------------
/**
 *	@brief	BGリボン書き込み
 *
 *	@param	MUSEUM_PK_WORK* wk
 *	@param	px
 *	@param	py
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void bg_ribbon_write( MUSEUM_PK_WORK* wk, s16 px, s16 py )
{
	enum { RIBBON_SX = 2, RIBBON_SY = 2, };

	int i, j;

	for( i=0; i<RIBBON_SY; i++ )
	{
		for( j=0; j<RIBBON_SX; j++ )
		{
			u16 write_chr = BG_M_CGX_RIBBON_HEAD + ( i * RIBBON_SY + j );
			GF_BGL_ScrWrite( wk->p_bgl, FRM_M_RIBBON, &write_chr, px + j, py + i, 1, 1 );
		}
	}

}

//-----------------------------------------------------------------------------
/**
 *	@brief	BGリボン更新
 *
 *	@param	MUSEUM_PK_WORK* wk
 *	@param	idx
 *	@param	monsno
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void bg_ribbon_flash( MUSEUM_PK_WORK* wk, u16 idx, u16 monsno )
{
	enum
	{
		DEF_PX = 6, DEF_PY = 4,
		DIFF_PX = 4, DIFF_PY = 3,
	};

	if( is_medalist( wk, monsno ) )
	{
		s16 px = DEF_PX + ( idx % OBJ_POKEICON_ROW ) * DIFF_PX;
		s16 py = DEF_PY + ( idx / OBJ_POKEICON_ROW ) * DIFF_PY;

		bg_ribbon_write( wk, px, py );
		GF_BGL_LoadScreenReq( wk->p_bgl, FRM_M_RIBBON );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケアイコン 表示切替
 *
 *	@param	MUSEUM_PK_WORK* wk
 *	@param	b_enable
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void pokeicon_enable( MUSEUM_PK_WORK* wk, BOOL b_enable )
{
	int cnt;
	for( cnt=0; cnt<OBJ_POKEICON_MAX; cnt++ )
	{
		u32 cap_idx = OBJ_ID_M_POKEICON_HEAD + cnt;
		CATS_ObjectEnableCap( wk->cap[ cap_idx ], b_enable );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケアイコン 更新
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void pokeicon_flash( MUSEUM_PK_WORK* wk )
{
	int cnt;
	u8 draw_max = get_page_poke_cnt( wk );
	MONS_DATA mons = {0};

//	HOSAKA_PRINT( "page monsno:\n" );

	// BGリボンをクリア
	GF_BGL_ScrClear( wk->p_bgl, FRM_M_RIBBON );
	// 一旦全てのアイコンを消す
	pokeicon_enable( wk, FALSE );

	for( cnt=0; cnt < draw_max; cnt++ )
	{
		u16 monsno = wk->c_draw_pklist[ OBJ_POKEICON_MAX * wk->page_pos + cnt ];
		u32 cap_idx = OBJ_ID_M_POKEICON_HEAD + cnt;

		if( cnt > 0 && cnt % 10 == 0 ){ HOSAKA_PRINT( "\n" ); }
//		HOSAKA_PRINT( "%03d ", monsno );

		// ロード
		mons.MonsNo = monsno;
		mons.Form	= get_poke_form( wk, monsno );
		MUSEUM_OBJ_POKEICON_Draw( wk->wk_obj, wk->cap[ cap_idx ], &mons, TRUE, FALSE );
		CATS_ObjectEnableCap( wk->cap[ cap_idx ], TRUE );

		// BG リボン
		bg_ribbon_flash( wk, cnt, monsno );
	}

//	HOSAKA_PRINT( "\n" );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ更新処理
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_flash( MUSEUM_PK_WORK* wk )
{
	// 矢印OBJ表示切替
	BOOL b_draw_l = ( wk->c_page_max > 0 && wk->page_pos > 0 );
	BOOL b_draw_r = ( wk->c_page_max > 0 && wk->page_pos < wk->c_page_max );

	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_M_ARROW_L ], b_draw_l );
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_M_ARROW_R ], b_draw_r );

	// ページ数表示
	MUSEUM_BMPWIN_RegistNum( wk->wk_msg, wk->page_pos + 1, 2, 0 );
	MUSEUM_BMPWIN_RegistNum( wk->wk_msg, wk->c_page_max + 1, 2, 1 );
	MUSEUM_BMPWIN_PrintRegStrWithPos( wk->wk_msg, BMPWIN_ID_M_PAGE, msg_pkthRNK_pkpage, 0, 0 );
}


//-----------------------------------------------------------------------------
/**
 *	@brief	ページの切替処理（ページ移動演出）
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL page_change( MUSEUM_PK_WORK* wk )
{
	enum
	{
		LOAD_FRAME = 4,
		MOVE_FRAME = LOAD_FRAME * 2,
		MOVE_VAL = 256 / LOAD_FRAME,
	};

	int i;
	int scr_val = MOVE_VAL * ( ( wk->b_page_move_right ) ? 1 : -1 );

	// 初期化処理
	if( wk->page_cnt == 0 )
	{
		int now_pos = CURSORMOVE_PosGet( wk->wk_cur );

		page_flash( wk );

		// 「もどる」の時は上画面非表示
		if( now_pos == CURID_RETURN )
		{
			element_null( wk );
		}
		else
		{
			element_flash( wk );
		}
	}
	// ロード処理
	else if( wk->page_cnt == LOAD_FRAME )
	{
		pokeicon_flash( wk );

		// pokeicon 描画
		for( i=0; i<OBJ_POKEICON_MAX; i++ )
		{
			s16 ox, oy;
			int ret_val = wk->page_cnt * scr_val;

			CATS_ObjectPosGetCap( wk->cap[ OBJ_ID_M_POKEICON_HEAD + i ], &ox, &oy );
			CATS_ObjectPosSetCap( wk->cap[ OBJ_ID_M_POKEICON_HEAD + i ], ox - ret_val * 2, oy );
		}
	}

	// 移動処理
	if( wk->page_cnt < MOVE_FRAME )
	{
		// bg
		GF_BGL_ScrollReq( wk->p_bgl, FRM_M_BOX, GF_BGL_SCROLL_X_INC, scr_val * -1 );
		GF_BGL_ScrollReq( wk->p_bgl, FRM_M_RIBBON, GF_BGL_SCROLL_X_INC, scr_val * -1 );

		// pokeicon
		for( i=0; i<OBJ_POKEICON_MAX; i++ )
		{
			CATS_ObjectPosMoveCap( wk->cap[ OBJ_ID_M_POKEICON_HEAD + i ], scr_val, 0 );
		}
	}
	// 終了処理
	else
	{
		// bg
		GF_BGL_ScrollReq( wk->p_bgl, FRM_M_BOX,		GF_BGL_SCROLL_X_SET, 0 );
		GF_BGL_ScrollReq( wk->p_bgl, FRM_M_RIBBON,	GF_BGL_SCROLL_X_SET, 0 );

		wk->page_cnt = 0;

		// カーソルを出す
		CATS_ObjectEnableCap( wk->cap[ OBJ_ID_M_CURSOR ], CATS_ENABLE_TRUE );

		return TRUE;
	}

	wk->page_cnt++;

	return FALSE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケグラ 更新処理
 *
 *	@param	MUSEUM_PK_WORK* wk
 *	@param	monsno
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void pokegra_flash( MUSEUM_PK_WORK* wk, u16 monsno )
{
	MONS_DATA mons = {0};

	// 図鑑と同じフォルム、ぶちにする
	mons.MonsNo = monsno;
	mons.Form	= get_poke_form( wk, monsno );
	mons.Sex	= get_poke_sex( wk, monsno );
	if( monsno == MONSNO_PATTIIRU )
	{
		mons.Rnd = get_pattiru_rand( wk );
	}
	MUSEUM_OBJ_POKEGRA_Trans( wk->cap[ OBJ_ID_S_POKEGRA ], &mons, FALSE, FALSE, wk->heapID );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	マス移動時の更新処理
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void element_flash( MUSEUM_PK_WORK* wk )
{
	u16 monsno = get_select_monsno( wk );

	if( monsno > MONSNO_END )
	{
		monsno = 0;
	}

	// ポケグラ
	pokegra_flash( wk, monsno );
	// ポケモン名を表示
	MUSEUM_BMPWIN_PrintPokemonName( wk->wk_msg, BMPWIN_ID_S_PKNAME, monsno );
	// メダル表示切替
	medal_check( wk, monsno );
	// メダリスト判定
	GF_Disp_GXS_VisibleControl( FRM_S_RIBBON_DISP, is_medalist( wk, monsno ) );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	空データを表示
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void element_null( MUSEUM_PK_WORK* wk )
{
	int i;

	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_S_POKEGRA ], CATS_ENABLE_FALSE );
	MUSEUM_BMPWIN_PrintPokemonName( wk->wk_msg, BMPWIN_ID_S_PKNAME, 0 );

	for( i=0; i<MEDAL_MAX; i++ )
	{
		CATS_ObjectEnableCap( wk->cap[ OBJ_ID_S_MEDAL_HEAD + i ], CATS_ENABLE_FALSE );
	}

	// 上画面メダリスト リボンBGをクリア
	GF_Disp_GXS_VisibleControl( FRM_S_RIBBON_DISP, FALSE );
}

//=============================================================================
/**
 *								外部公開関数
 */
//=============================================================================


//==============================================================================
/**
 *	@brief	プロセス初期化
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
//==============================================================================
PROC_RESULT MuseumPokemonProc_Init( PROC *proc, int *seq)
{
	MUSEUM_PK_WORK *wk = NULL;
	PKTH_MUSEUM_PK_PARAM * p_param;

	Overlay_Load( FS_OVERLAY_ID(pkthln_common), OVERLAY_LOAD_NOT_SYNCHRONIZE );

	p_param = (PKTH_MUSEUM_PK_PARAM*)PROC_GetParentWork( proc );

	// DISP初期化
	GF_Disp_GXS_VisibleControlInit();
	GF_Disp_GX_VisibleControlInit();

	GF_ASSERT( p_param );

	//ヒープ作成
	sys_CreateHeap( HEAPID_BASE_APP, HEAPID_PKTH_MUSEUM, 0x30000 );

	wk = PROC_AllocWork( proc, sizeof(MUSEUM_PK_WORK), HEAPID_PKTH_MUSEUM );
	MI_CpuClear8( wk, sizeof(MUSEUM_PK_WORK) );

	// パラメータ設定
	wk->heapID	= HEAPID_PKTH_MUSEUM;
	wk->p_prm	= p_param;

	// 汎用初期化処理
	MUSEUM_COMMON_Init();

	// アーカイブオープン
	wk->p_arc_pkth_museum = ArchiveDataHandleOpen( ARC_PKTH_MUSEUM_GRA, wk->heapID );
	wk->p_arc_zkn = ArchiveDataHandleOpen( ARC_ZUKAN_DATA, wk->heapID );

	// 参照データの展開
	data_setup( wk );

	// BG初期化
	BG_Init( wk );
	BG_LoadRes( wk );
	wk->wk_msg = MUSEUM_BMPWIN_Create( wk->heapID, wk->p_bgl, BMPWIN_ID_MAX, c_BmpWinList, NARC_msg_pokethlon_museum_dat );

	// OBJ初期化
	OBJ_Init( wk );

	// カーソル初期化
	CURSOR_Init( wk );

	// 初期表示
	page_flash( wk );
	pokeicon_flash( wk );
	element_flash( wk );

	// 一度だけ描画すれば良い文字列を描画
	PRINT_StaticMessage( wk );

	WIPE_ResetWndMask( WIPE_DISP_MAIN );
	WIPE_ResetWndMask( WIPE_DISP_SUB );

	sys_VBlankFuncChange( COMMON_VBlank, wk );

	return PROC_RES_FINISH;
}

//==============================================================================
/**
 *	@brief	プロセス終了
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
//==============================================================================
PROC_RESULT MuseumPokemonProc_End( PROC *proc,int *seq)
{
	MUSEUM_PK_WORK* wk = PROC_GetWork( proc );

	// -- 図鑑データを開放
	sys_FreeMemoryEz( wk->cp_pklist );

	// -- Cursor
	CURSOR_Release( wk );

	// -- OBJ
	MUSEUM_OBJ_Delete( wk->wk_obj, wk->cap, OBJ_ID_MAX );

	// -- BG
	MUSEUM_BMPWIN_Delete( wk->wk_msg, BMPWIN_ID_MAX );
	BG_Release( wk );

	// -- COMMON
	MUSEUM_COMMON_Release();

	//ワークエリア解放
	PROC_FreeWork( proc );

	sys_DeleteHeap( HEAPID_PKTH_MUSEUM );

	Overlay_UnloadID( FS_OVERLAY_ID(pkthln_common) );

	return PROC_RES_FINISH;

}

//==============================================================================
/**
 *	@brief	プロセスメイン
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
//==============================================================================
PROC_RESULT MuseumPokemonProc_Main( PROC *proc,int *seq)
{
	enum
	{
		MAIN_SEQ_INIT = 0,
		MAIN_SEQ_FADE_IN,
		MAIN_SEQ_MAIN,
		MAIN_SEQ_FADE_OUT,
		MAIN_SEQ_END,
	};

	MUSEUM_PK_WORK* wk = PROC_GetWork(proc);

	switch( *seq )
	{
		case MAIN_SEQ_INIT :
			WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN,
							0x0000, COMM_BRIGHTNESS_SYNC, 1, wk->heapID );
			(*seq) = MAIN_SEQ_FADE_IN;
			break;

		case MAIN_SEQ_FADE_IN :
			if( WIPE_SYS_EndCheck() )
			{
				(*seq) = MAIN_SEQ_MAIN;
			}
			break;

		case MAIN_SEQ_MAIN :
			if( wk->b_element_flash )
			{
				element_flash( wk );
				wk->b_element_flash = FALSE;
			}

			// ページ移動処理
			if( wk->b_page_flash )
			{
				if( page_change( wk ) )
				{
					wk->b_page_flash = FALSE;
				}
			}
			else
			{
				// カーソル処理, 終了判定
				if( CURSOR_Main( wk ) || MUSEUM_UTIL_CheckExit() )
				{
					Snd_SePlay( SEQ_SE_DP_SELECT );
					WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT,
									0x0000, COMM_BRIGHTNESS_SYNC, 1, wk->heapID );
					(*seq) = MAIN_SEQ_FADE_OUT;
				}
			}
			break;

		case MAIN_SEQ_FADE_OUT :
			if( WIPE_SYS_EndCheck() )
			{
				(*seq) = MAIN_SEQ_END;
			}
			break;

		case MAIN_SEQ_END :
			return PROC_RES_FINISH;

		default : GF_ASSERT( !"seq error!" );
	}

	MUSEUM_OBJ_Draw( wk->wk_obj );

	return PROC_RES_CONTINUE;
}

//=============================================================================
/**
 *								static関数
 */
//=============================================================================

//-----------------------------------------------------------------------------
/**
 *	@brief	VBlank処理
 *
 *	@param	* work
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
static void COMMON_VBlank( void* work )
{
	MUSEUM_PK_WORK* wk = work;

	CATS_RenderOamTrans();
	GF_BGL_VBlankFunc( wk->p_bgl );
	OS_SetIrqCheckFlag( OS_IE_V_BLANK );
}

static const CURSORMOVE_CALLBACK c_cur_cb = {
	CursorMoveCallBack_On,
	CursorMoveCallBack_Off,
	CursorMoveCallBack_Move,
	CursorMoveCallBack_Touch,
};

//-----------------------------------------------------------------------------
/**
 *	@brief	カーソル初期化
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CURSOR_Init( MUSEUM_PK_WORK* wk )
{
	wk->wk_cur = CURSORMOVE_Create(
					c_cur_hit,
					c_cur_pos,
					&c_cur_cb,
					wk,
					TRUE,
					wk->cur_pos,
					wk->heapID );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	カーソル開放
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CURSOR_Release( MUSEUM_PK_WORK* wk )
{
	if( wk->wk_cur != NULL ){
		CURSORMOVE_Exit( wk->wk_cur );
		wk->wk_cur = NULL;
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ移動
 *
 *	@param	MUSEUM_PK_WORK* wk
 *	@param	b_right
 *	@param	b_touch
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_move( MUSEUM_PK_WORK* wk, BOOL b_right, BOOL b_touch )
{
	u32 pre_pos = wk->page_pos;

	if( b_right )
	{
		wk->page_pos += 1;
	}
	else if( wk->page_pos > 0 )
	{
		wk->page_pos -= 1;
	}

	wk->page_pos = MATH_CLAMP( wk->page_pos, 0, wk->c_page_max );

	// ページ切替処理
	if( wk->page_pos != pre_pos )
	{
		Snd_SePlay( SEQ_SE_DP_SELECT );

		wk->b_page_move_right = (!b_right); // ボタンとは逆の方向に移動する
		wk->b_page_flash = TRUE;


		// カーソル位置修正
		{
			u8 pos = 0;
			int now_pos = CURSORMOVE_PosGet( wk->wk_cur );

			// タッチ
			if( b_touch )
			{
				// 戻るボタンのときは位置固定
				if( now_pos == CURID_RETURN )
				{
					pos = now_pos;
				}
			}
			// キー操作
			else
			{
				// 左右 回り込み
				pos = now_pos;
				if( b_right )	{ pos -= (OBJ_POKEICON_ROW-1); }
				else			{ pos += (OBJ_POKEICON_ROW-1); }
			}

			CURSORMOVE_PosSet( wk->wk_cur, pos );
			CursorObjMove( wk, pos );
		}

		// カーソルを一旦消す
		CATS_ObjectEnableCap( wk->cap[ OBJ_ID_M_CURSOR ], CATS_ENABLE_FALSE );

		HOSAKA_PRINT("page_move pos:%d \n", wk->page_pos );
	}
}


//-----------------------------------------------------------------------------
/**
 *	@brief	カーソル メインループ
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL CURSOR_Main( MUSEUM_PK_WORK* wk )
{
	int ret;
	u8 pos;
	int result;

	ret = CURSORMOVE_MainCont( wk->wk_cur );
	pos = CURSORMOVE_PosGet( wk->wk_cur );

	// ページ切替処理（ タッチ ）
	result = GF_TP_HitTrg( c_page_hit );

	// タッチ操作
	if( result != TP_HIT_NONE )
	{
		if( result == BTN_IDX_PAGE_LEFT )
		{
			page_move( wk, FALSE, TRUE );
		}
		else if( result == BTN_IDX_PAGE_RIGHT )
		{
			page_move( wk, TRUE, TRUE );
		}
	}
	// ページ切替処理( キー )
	else if( ret == CURSORMOVE_NONE && pos < CURID_POKE_MAX )
	{
		if( CHECK_REPEAT(PAD_KEY_LEFT) )
		{
			page_move( wk, FALSE, FALSE );
		}
		else if( CHECK_REPEAT(PAD_KEY_RIGHT) )
		{
			page_move( wk, TRUE, FALSE );
		}
	}
	else if( pos == CURID_RETURN && (sys.trg & PAD_BUTTON_DECIDE) )
	{
		return TRUE; // 終了
	}

	return FALSE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	カーソルOBJ 移動
 *
 *	@param	MUSEUM_PK_WORK* wk
 *	@param	pos
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CursorObjMove( MUSEUM_PK_WORK* wk, int pos )
{
	const POINTER_WORK * pw;
	u8	x, y;

	pw = CURSORMOVE_PointerWorkGet( wk->wk_cur, pos );

	PointerWkPosGet( pw, &x, &y );
	CATS_ObjectPosSetCap( wk->cap[ OBJ_ID_M_CURSOR ], x, y );


	// カーソル座標保持
	// ここで座標を格納してしまうとOBJが動かなかった時に更新されないが、
	// OBJと完全同期するはずなのでよしとする。
	wk->cur_pos = pos;

	Snd_SePlay( SEQ_SE_DP_SELECT );
}


//-----------------------------------------------------------------------------
/**
 *	@brief	カーソルモジュール用コールバック関数
 *
 *	@param	void * work
 *	@param	now_pos
 *	@param	old_pos
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CursorMoveCallBack_On( void * work, int now_pos, int old_pos )
{
	MUSEUM_PK_WORK* wk = work;

	CURSORMOVE_PosSet( wk->wk_cur, now_pos );
	CursorObjMove( wk, now_pos );

	HOSAKA_PRINT( "cursor on : now_idx:%d \n", now_pos );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	カーソルモジュール用コールバック関数
 *
 *	@param	void * work
 *	@param	now_pos
 *	@param	old_pos
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CursorMoveCallBack_Off( void * work, int now_pos, int old_pos )
{
	MUSEUM_PK_WORK* wk = work;

	HOSAKA_PRINT( "cursor off\n" );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	カーソルモジュール用コールバック関数
 *
 *	@param	void * work
 *	@param	now_pos
 *	@param	old_pos
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CursorMoveCallBack_Move( void * work, int now_pos, int old_pos )
{
	MUSEUM_PK_WORK* wk = work;
	cursor_move( wk, now_pos, old_pos, FALSE );
	HOSAKA_PRINT( "cursor move\n" );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	カーソルモジュール用コールバック関数
 *
 *	@param	void * work
 *	@param	now_pos
 *	@param	old_pos
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CursorMoveCallBack_Touch( void * work, int now_pos, int old_pos )
{
	MUSEUM_PK_WORK* wk = work;
	cursor_move( wk, now_pos, old_pos, TRUE );
	HOSAKA_PRINT( "cursor touch\n" );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	カーソル移動処理
 *
 *	@param	MUSEUM_PK_WORK* wk
 *	@param	now_pos
 *	@param	old_pos
 *	@param	b_touch
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void cursor_move( MUSEUM_PK_WORK* wk, int now_pos, int old_pos, BOOL b_touch )
{
	if( now_pos != old_pos && NELEMS(c_cur_hit) > now_pos )
	{
		HOSAKA_PRINT( "now_pos:%d old_pos:%d \n", now_pos, old_pos );

		CursorObjMove( wk, now_pos );

		if( now_pos < CURID_POKE_MAX )
		{
			// ポケモン情報更新
			wk->b_element_flash = TRUE;
		}
		else
		{
			// ポケモン情報クリア
			element_null( wk );
		}

		// カーソルのAnimeSeq変更
		{
			u32 seq;

			if( now_pos == CURID_RETURN )
			{
				seq = NANR_obj_trophy_cur_btn;
			}
			else
			{
				seq = NANR_obj_trophy_cur_pk;
			}
			if( b_touch ){ seq += 1; }

			CATS_ObjectAnimeSeqSetCap( wk->cap[ OBJ_ID_M_CURSOR ], seq );
		}
	}
}


//-----------------------------------------------------------------------------
/**
 *	@brief	BG 初期化
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_Init( MUSEUM_PK_WORK* wk )
{
	wk->p_bgl = GF_BGL_BglIniAlloc( wk->heapID );

	{	//BG SYSTEM
		GF_BGL_SYS_HEADER BGsys_data = {
			GX_DISPMODE_GRAPHICS,GX_BGMODE_0,GX_BGMODE_0,GX_BG0_AS_2D
		};
		GF_BGL_InitBG(&BGsys_data);
	}

	{
		int i;
		GF_BGL_BGCNT_HEADER TextBgCntDat[ BG_USE_NUM ] = {
			// -- MAIN --
			{	// FRM_M_BASE BG0
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x0000,GX_BG_CHARBASE_0x04000,GX_BG_EXTPLTT_01,
				3,0,0,FALSE
			},
			{	//FRM_M_TEXT BG1
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x0800,GX_BG_CHARBASE_0x0c000,GX_BG_EXTPLTT_01,
				0,0,0,FALSE
			},
			{	//FRM_M_BOX BG2
				0,0,0x1000,0,GF_BGL_SCRSIZ_512x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x1000,GX_BG_CHARBASE_0x14000,GX_BG_EXTPLTT_01,
				2,0,0,FALSE
			},
			{	//FRM_M_RIBBON BG3
				0,0,0x1000,0,GF_BGL_SCRSIZ_512x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x2000,GX_BG_CHARBASE_0x18000,GX_BG_EXTPLTT_01,
				0,0,0,FALSE
			},
			// -- SUB --
			{	// FRM_S_BASE BG0
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xf800,GX_BG_CHARBASE_0x00000,GX_BG_EXTPLTT_01,
				3,0,0,FALSE
			},
			{	// FRM_S_TEXT BG1
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xf000,GX_BG_CHARBASE_0x04000,GX_BG_EXTPLTT_01,
				0,0,0,FALSE
			},
			{	// FRM_S_RIBBON BG2
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xd800,GX_BG_CHARBASE_0x08000,GX_BG_EXTPLTT_01,
				0,0,0,FALSE
			},
		};

		for( i=0; i<BG_USE_NUM; i++ )
		{
			GF_BGL_BGControlSet(wk->p_bgl, c_BG_UseList[i], &(TextBgCntDat[i]), GF_BGL_MODE_TEXT);
			GF_BGL_ScrClear(wk->p_bgl, c_BG_UseList[i]);
			GF_BGL_ClearCharSet(c_BG_UseList[i], 32, 0, wk->heapID);
		}
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BG リソースロード
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_LoadRes( MUSEUM_PK_WORK* wk )
{
	enum { BG_PALSIZE = 0x20 * 2, };

	//----------------------------------------------------
	// Main LCD
	ArcUtil_HDL_PalSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_NCLR, PALTYPE_MAIN_BG, 0, BG_PALSIZE, wk->heapID );

	// -- base --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_lz_NCGR,
						wk->p_bgl, FRM_M_BASE, 0, 0, TRUE, wk->heapID );

	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_lz_NSCR,
						wk->p_bgl, FRM_M_BASE, 0, 0, TRUE, wk->heapID );

	// -- box --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_lz_NCGR,
						wk->p_bgl, FRM_M_BOX, 0, 0, TRUE, wk->heapID );

	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_box_lz_NSCR,
						wk->p_bgl, FRM_M_BOX, 0, 0, TRUE, wk->heapID );

	// -- ribbon --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_ribbon_lz_NCGR,
						wk->p_bgl, FRM_M_RIBBON, BG_M_CGX_RIBBON_HEAD, 0, TRUE, wk->heapID );

	//----------------------------------------------------
	// Sub LCD
	ArcUtil_HDL_PalSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_sub_NCLR, PALTYPE_SUB_BG, 0, BG_PALSIZE, wk->heapID );

	// -- base --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_sub_lz_NCGR,
						wk->p_bgl, FRM_S_BASE, 0, 0, TRUE, wk->heapID );

	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_sub_lz_NSCR,
						wk->p_bgl, FRM_S_BASE, 0, 0, TRUE, wk->heapID );

	// -- ribbon --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_sub_lz_NCGR,
						wk->p_bgl, FRM_S_RIBBON, 0, 0, TRUE, wk->heapID );

	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_poke_bg_sub_ribbon_lz_NSCR,
						wk->p_bgl, FRM_S_RIBBON, 0, 0, TRUE, wk->heapID );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BG 開放
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
static void BG_Release( MUSEUM_PK_WORK* wk )
{
	u8 i = 0;

	ArchiveDataHandleClose( wk->p_arc_zkn );
	ArchiveDataHandleClose( wk->p_arc_pkth_museum );

	for( i=0; i<BG_USE_NUM; i++ )
	{
		GF_BGL_BGControlExit( wk->p_bgl, c_BG_UseList[i] );
	}

	sys_FreeMemoryEz( wk->p_bgl );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJ 初期化処理
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_Init( MUSEUM_PK_WORK* wk )
{
	TCATS_RESOURCE_NUM_LIST crnl = { CHR_ID_MAX, PAL_ID_MAX, CEL_ID_MAX, ANM_ID_MAX, 0 };

	wk->wk_obj = MUSEUM_OBJ_Create( wk->heapID, &crnl, OBJ_ID_MAX );

	OBJ_LoadRes( wk );

	OBJ_AddCommon( wk );
	OBJ_AddMedal( wk );
	OBJ_AddPokeIcon( wk );

//	if( is_museum_open( wk ) )
	{
		static const MUSEUM_OBJ_ID objID_M = { CHR_ID_M_TROPHY, PAL_ID_M_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, };
		MUSEUM_OBJ_AddMater( wk->wk_obj, wk->cap, &objID_M, get_trophy_num(wk), OBJ_ID_M_MATER_HEAD, 1*8, 19*8, TRUE );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケグラ用ダミーリソースをロード
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_PokegraLoadResDummy( MUSEUM_PK_WORK* wk )
{
	static const MUSEUM_OBJ_ID idx_tbl = {
		CHR_ID_S_POKEGRA, PAL_ID_S_POKEGRA, CEL_ID_POKEGRA, ANM_ID_POKEGRA,
	};

	CATS_SYS_PTR	csp = MUSEUM_OBJ_GetCsp( wk->wk_obj );
	CATS_RES_PTR	crp = MUSEUM_OBJ_GetCrp( wk->wk_obj );

	MUSEUM_OBJ_POKEGRA_LoadResDummy( csp, crp, &idx_tbl, NNS_G2D_VRAM_TYPE_2DSUB );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJ リソースロード
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_LoadRes( MUSEUM_PK_WORK* wk )
{
	CATS_SYS_PTR	csp = MUSEUM_OBJ_GetCsp( wk->wk_obj );
	CATS_RES_PTR	crp = MUSEUM_OBJ_GetCrp( wk->wk_obj );

	// -- obj_trophy --
	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_TROPHY );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_TROPHY );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NCER, TRUE, CEL_ID_TROPHY );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NANR, TRUE, ANM_ID_TROPHY );

	// -- obj_medal --
	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_medal_NCLR, 0, 5, NNS_G2D_VRAM_TYPE_2DSUB, PAL_ID_S_MEDAL );

	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_medal_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DSUB, CHR_ID_S_MEDAL );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_medal_lz_NCER, TRUE, CEL_ID_MEDAL );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_medal_lz_NANR, TRUE, ANM_ID_MEDAL );

	// -- poke_obj --
	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_poke_obj_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_POKEREC );

	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_poke_obj_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_POKEREC );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_poke_obj_lz_NCER, TRUE, CEL_ID_POKEREC );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_poke_obj_lz_NANR, TRUE, ANM_ID_POKEREC );

	// -- pokeicon用リソース
	{
		static const MUSEUM_OBJ_ID c_pkicon_id = {
			CHR_ID_M_POKEICON_HEAD, PAL_ID_M_POKEICON, CEL_ID_POKEICON, ANM_ID_POKEICON,
		};
		MUSEUM_OBJ_POKEICON_LoadRes( wk->wk_obj, &c_pkicon_id, OBJ_POKEICON_MAX, TRUE, FALSE );
	}

	// -- pokegra用リソース
	OBJ_PokegraLoadResDummy( wk );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	通常OBJロード
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_AddCommon( MUSEUM_PK_WORK* wk )
{
	static const TCATS_OBJECT_ADD_PARAM_S common_prm[ OBJ_ID_COMMON_MAX ] =
	{
		{ // OBJ_ID_M_CURSOR
			TRAYPOKE_PX(0)+PICUR_X, TRAYPOKE_PY(0)+PICUR_Y,	0,
			NANR_obj_trophy_cur_pk, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_TROPHY, PAL_ID_M_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, 0, 0 }, 0, FALSE,
		},
		{ // OBJ_ID_M_ARROW_L
			OBJPOS_ARROW_L_X, OBJPOS_ARROW_Y, 0,
			OBJ_ANM_ARROW_L, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_POKEREC, PAL_ID_M_POKEREC, CEL_ID_POKEREC, ANM_ID_POKEREC, 0, 0 }, 0, FALSE,
		},
		{ // OBJ_ID_M_ARROW_R
			OBJPOS_ARROW_R_X, OBJPOS_ARROW_Y, 0,
			OBJ_ANM_ARROW_R, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_POKEREC, PAL_ID_M_POKEREC, CEL_ID_POKEREC, ANM_ID_POKEREC, 0, 0 }, 0, FALSE,
		},
		{ // OBJ_ID_S_POKEGRA
			8*6, 8*14, 0,
			0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
			{ CHR_ID_S_POKEGRA, PAL_ID_S_POKEGRA, CEL_ID_POKEGRA, ANM_ID_POKEGRA, 0, 0 }, 1, FALSE,
		},
	};

	int i;

	for( i=0; i < OBJ_ID_COMMON_MAX; i++ )
	{
		wk->cap[i] = MUSEUM_OBJ_Add( wk->wk_obj, &common_prm[ i ] );
		CATS_ObjectAutoAnimeSetCap( wk->cap[ i ], TRUE );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	メダルをロード
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_AddMedal( MUSEUM_PK_WORK* wk )
{
	static const pos_x_tbl[] = { 0, 2, 3, 2, 0 };

	int i;
	TCATS_OBJECT_ADD_PARAM_S prm = {0};

	for( i=0; i<OBJ_MEDAL_MAX; i++ )
	{
		int cap_idx = OBJ_ID_S_MEDAL_HEAD + i;

		prm.anm = i;
		prm.pal = i;
		prm.id[0] = CHR_ID_S_MEDAL;
		prm.id[1] = PAL_ID_S_MEDAL;
		prm.id[2] = CEL_ID_MEDAL;
		prm.id[3] = ANM_ID_MEDAL;
		prm.d_area = NNS_G2D_VRAM_TYPE_2DSUB;
		prm.x = 13*8 + pos_x_tbl[i]*8;
		prm.y = 6*8 + i * 4*8;

		wk->cap[ cap_idx ] = MUSEUM_OBJ_Add( wk->wk_obj, &prm );
		CATS_ObjectAutoAnimeSetCap( wk->cap[ cap_idx ], TRUE );
		CATS_ObjectEnableCap( wk->cap[ cap_idx ], CATS_ENABLE_FALSE );
	}


}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケモンアイコンのロード
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_AddPokeIcon( MUSEUM_PK_WORK* wk )
{
	u32 i, j;
	TCATS_OBJECT_ADD_PARAM_S prm = {0};
	const s16 def_x = TRAYPOKE_PX(0)+PICUR_X;
	const s16 def_y = TRAYPOKE_PY(0)+PICUR_Y - 4;

	for( i=0; i < OBJ_POKEICON_LINE; i++ )
	{
		for( j=0; j < OBJ_POKEICON_ROW; j++ )
		{
			int cap_idx = OBJ_ID_M_POKEICON_HEAD + ( i * OBJ_POKEICON_ROW + j );

			prm.id[ 0 ] = CHR_ID_M_POKEICON_HEAD + ( i * OBJ_POKEICON_ROW + j );
			prm.id[ 1 ] = PAL_ID_M_POKEICON;
			prm.id[ 2 ] = CEL_ID_POKEICON;
			prm.id[ 3 ] = ANM_ID_POKEICON;
			prm.d_area = NNS_G2D_VRAM_TYPE_2DMAIN;
			prm.x = def_x + j * OBJ_TRAYPOKE_SX;
			prm.y = def_y + i * OBJ_TRAYPOKE_SY;
			prm.bg_pri = OBJ_BGPRI_POKEICON;

			wk->cap[ cap_idx ] = MUSEUM_OBJ_Add( wk->wk_obj, &prm );
//			CATS_ObjectAutoAnimeSetCap( wk->cap[ cap_idx ], TRUE );
		}
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	固定メッセージ（一度きりの描画で良いもの）
 *
 *	@param	MUSEUM_PK_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PRINT_StaticMessage( MUSEUM_PK_WORK* wk )
{
	int i;
	WORDSET* wset = MUSEUM_BMPWIN_GetWordset( wk->wk_msg );

	// メダリストポケモン
	MUSEUM_BMPWIN_PrintAndSelectBackColor( wk->wk_msg, BMPWIN_ID_S_MDLST_CAP, msg_pkthRNK_pkmdlist, FONT_POS_RIBBON_BACK );
	MUSEUM_BMPWIN_PrintAndSetOfs( wk->wk_msg, BMPWIN_ID_M_MODE_CAP, msg_pkthRNK_pkcap, 1, 0 );
	MUSEUM_BMPWIN_PrintEx( wk->wk_msg, BMPWIN_ID_M_RETURN, msg_pkthRNK_return, FALSE, 0, FONT_TOUCH );

	// ポケモン名のキャプション
	MUSEUM_BMPWIN_Print(wk->wk_msg, BMPWIN_ID_S_PKNAME_CAP, msg_pkthRNK_pkname, FALSE );

	// メダル名
	for( i=0; i<OBJ_MEDAL_MAX; i++ )
	{
		WORDSET_RegisterPkthlnMedal( wset, 0, i );
		MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_ID_S_MDL_SPD + i, msg_pkthRNK_mdl, FALSE );
	}

	// メダリストの数
	WORDSET_RegisterNumber( wset, 0, get_medalist_cnt( wk ), 3, NUMBER_DISPTYPE_SPACE, NUMBER_CODETYPE_DEFAULT );
	MUSEUM_BMPWIN_PrintAndSetOfs( wk->wk_msg, BMPWIN_ID_M_MDLIST_CNT, msg_pkthRNK_pkmdlist_cnt, 1, 0 );

	if( is_museum_open( wk ) )
	{
		MUSEUM_BMPWIN_PrintAndSetOfs( wk->wk_msg, BMPWIN_ID_M_TROPHY_TAR, msg_pkthRNK_pktrophy_01 + get_trophy_num( wk ), 1, 0 );
	}
}

